<template>
  <a-card :bordered="false">
    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        :customRow="customRow"
        @change="handleTableChange">
        <span slot="notify" slot-scope="text, record">
          <a-icon title="催办提醒" v-if="record.taskUrge" theme="twoTone" twoToneColor="#eb2f96"
                  @click="taskNotifyMe(flowCode,record.id)" type="notification"/>
          {{ text }}
        </span>
        <template slot="status" slot-scope="status">
          <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt=""
               style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="pcaSlot" slot-scope="text">
          <div>{{ getPcaText(text) }}</div>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
            <template v-if="record.bpmStatus === '1'">
            <a-button
              class="ruleButton"
              :ghost="true"
              type="primary"
              icon="edit"
              @click="handleEdit(record)"
              :disabled="isDisabledAuth('erpOmcTenderFile:edit')"
            />
            <a-divider type="vertical"/>
            <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                <a-button
                  class="ruleButton"
                  :ghost="true"
                  type="primary"
                  icon="delete"
                  :disabled="isDisabledAuth('erpOmcTenderFile:delete')"/>
            </a-popconfirm>
            <a-divider type="vertical"/>
            <a-button type="primary" size="small" @click="startProcess(record)"
                      :disabled="isDisabledAuth('erpOmcTenderFile:startProcess')">发起流程</a-button>
        </template>
        <template v-else-if="showBtn(record.bpmStatus)&&queryParam.bizTaskType=='1'">
            <a-button type="primary" size="small" @click="handleProcess(record)">办理</a-button>
            <a-divider type="vertical"/>
        </template>
        <template v-else-if="queryParam.bizTaskType=='2' && showBtn(record.bpmStatus)">
            <a-button type="primary" size="small" @click="taskNotify(flowCode,record.id)">催办</a-button>
            <a-divider type="vertical"/>
            <a-popconfirm title="确定要作废吗?" @confirm="() => invalidProcess(record)">
                <a-button type="primary" size="small" :disabled="isDisabledAuth('erpOmcTenderFile:invalidProcess')">
                    作废流程
                </a-button>
            </a-popconfirm>
            <a-divider type="vertical"/>
        </template>
        <template v-if="record.bpmStatus !== '1'">
            <a-button type="primary" size="small" @click="handleTrack(record)"
                      :disabled="isDisabledAuth('erpOmcTenderFile:viewTrack')">审批进度</a-button>
        </template>
        </span>

      </a-table>
    </div>

    <erp-omc-tender-file-modal ref="modalForm" @ok="modalFormOk"></erp-omc-tender-file-modal>
    <bpm-biz-task-deal-modal ref="taskDealModal" :path="path" :formData="formData"
                             @ok="handleOk"></bpm-biz-task-deal-modal>
    <bpm-process-track-modal ref="bpmProcessTrackModal"></bpm-process-track-modal>
    <biz-task-notify-modal ref="taskNotifyModal"></biz-task-notify-modal>
    <biz-task-notify-me-modal ref="taskNotifyMeModal"></biz-task-notify-me-modal>
  </a-card>
</template>

<script>

import '@assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgBpmListMixin } from '@/mixins/JeecgBpmListMixin'
import BpmBizTaskDealModal from '@views/modules/bpmbiz/common/BpmBizTaskDealModal.vue';
import BpmProcessTrackModal from '@views/modules/bpmbiz/common/BpmProcessTrackModal.vue';
import BizTaskNotifyModal from '@views/modules/bpmbiz/common/BizTaskNotifyModal.vue';
import BizTaskNotifyMeModal from '@views/modules/bpmbiz/common/BizTaskNotifyMeModal.vue';
import ErpOmcTenderFileModal from '@views/erp/omc/tenderfile/modules/ErpOmcTenderFileModal.vue'
import { httpAction } from '@api/manage'
import Area from '@comp/_util/Area'
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
import SelectCustomerInput from '@views/scy/components/SelectCustomerInput'

export default {
  name: 'ErpOmcTenderFileList',
  mixins: [JeecgBpmListMixin, mixinDevice, DisabledAuthFilterMixin],
  components: {
    ErpOmcTenderFileModal,
    BpmBizTaskDealModal,
    BpmProcessTrackModal,
    BizTaskNotifyModal,
    BizTaskNotifyMeModal,
    SelectCustomerInput,
    SelectUserByDep
  },
  data() {
    return {
      description: '投标文件台账管理页面',
      //表头
      columns: [],
      //列设置
      settingColumns: [],
      // 列定义
      defColumns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '标书文件编号',
          align: 'center',
          dataIndex: 'bidNo',
        },
        {
          title: '项目名称',
          align: 'center',
          dataIndex: 'projectName',
        },
        {
          title: '项目类型',
          align: 'center',
          dataIndex: 'projectType_dictText',
        },
        {
          title: '经营团队',
          align: 'center',
          dataIndex: 'businessTeam_dictText',
        },
        {
          title: '申请人',
          align: 'center',
          dataIndex: 'proposer_dictText',
        },
        {
          title: '审核状态',
          align: 'center',
          dataIndex: 'bpmStatus_dictText',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action'
          }
        }
      ],
      url: {
        list: '/api/erp/omc/tenderfile/erpOmcTenderFile/list',
        list0: '/api/erp/omc/tenderfile/erpOmcTenderFile/list?tenderId=',
        delete: '/api/erp/omc/tenderfile/erpOmcTenderFile/delete',
        deleteBatch: '/api/erp/omc/tenderfile/erpOmcTenderFile/deleteBatch',
        exportXlsUrl: '/api/erp/omc/tenderfile/erpOmcTenderFile/exportXls',
        importExcelUrl: 'api/erp/omc/tenderfile/erpOmcTenderFile/importExcel',
        bizCount: '/api/erp/omc/tenderfile/erpOmcTenderFile/bizCount',
        queryAddParameter: '/api/erp/omc/tenderfile/erpOmcTenderFile/queryAddParameter',
      },
      //代码生成后需手动设置流程编码
      flowCode: 'dev_erp_omc_tender_file_001',
      formUrl: 'scy/omc/tenderfile/modules/ErpOmcTenderFileForm',
      formUrlMobile: '',
      dictOptions: {},
      pcaData: '',
      superFieldList: [],
      disableMixinCreated: true,
      colsettings: 'ErpOmcTenderFile:colsettings',
    }
  },
  created() {
    this.pcaData = new Area()
    this.getSuperFieldList();
    this.url.list = this.url.list0 + this.$route.params.id;
    this.loadData();
    this.initColumns();
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    },
  },
  methods: {
    customRow(record) {
      return {
        on: {
          // 事件
          dblclick: event => {
            this.handleDetail(record)
          }
        }
      }
    },
    handleDetail: function (record) {
      const _path = this.$route.path
      this.$router.push({
        path: `/erp/omc/tenderfile/ErpOmcTenderFileListDetail/${record.id}`
      })
    },
    handleAddDiy() {
      let httpurl = '';
      let method = '';
      httpurl += this.url.queryAddParameter;
      method = 'POST';
      httpAction(httpurl, this.model, method).then((res) => {
        this.$nextTick(() => {
          this.$refs.modalForm.add(res.result);
          this.$refs.modalForm.title = '新增';
          this.$refs.modalForm.disableSubmit = false;
        })
      })
    },
    getPcaText(code) {
      return this.pcaData.getText(code);
    },
    initDictConfig() {
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({ type: 'datetime', value: 'createTime', text: '日期' })
      fieldList.push({ type: 'string', value: 'proposer', text: '经办人id', dictCode: '' })
      fieldList.push({ type: 'sel_depart', value: 'proposerDeptId', text: '经办人部门ID' })
      fieldList.push({ type: 'string', value: 'tenderId', text: '投标申请id', dictCode: 'erp_omc_tender,project_name,id' })
      fieldList.push({ type: 'string', value: 'bidNo', text: '标书文件编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'projectName', text: '项目名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'projectType', text: '项目类型', dictCode: 'xmlx_type' })
      fieldList.push({ type: 'string', value: 'undertaker', text: '承接人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'year', text: '业绩归属年度', dictCode: 'yjgsnd' })
      fieldList.push({ type: 'pca', value: 'projectAddress', text: '项目地址' })
      fieldList.push({ type: 'string', value: 'businessTeam', text: '经营团队', dictCode: '' })
      fieldList.push({ type: 'date', value: 'entriesEndDate', text: '报名截止日期' })
      fieldList.push({ type: 'date', value: 'tenderEndDate', text: '投标截止日期' })
      fieldList.push({ type: 'string', value: 'ownerUnit', text: '业主单位', dictCode: '' })
      fieldList.push({ type: 'string', value: 'ownerLinkman', text: '业主联系人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'tenderAgent', text: '招标代理联系人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'biddingMethod', text: '招标方式', dictCode: 'bidding_method' })
      fieldList.push({ type: 'string', value: 'controlPrice', text: '招标控制价（元）', dictCode: '' })
      fieldList.push({ type: 'string', value: 'difficultyCoefficient', text: '难度系数', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bidFee', text: '标书费（元）', dictCode: '' })
      fieldList.push({ type: 'string', value: 'tenderBond', text: '投标保证金（元）', dictCode: '' })
      fieldList.push({ type: 'string', value: 'feeReturn', text: '投标保证金归还人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'platformFee', text: '会员平台费（元）', dictCode: '' })
      fieldList.push({ type: 'string', value: 'tenderContent', text: '投标内容概要', dictCode: '' })
      fieldList.push({ type: 'string', value: 'tenderFile', text: '招标文件', dictCode: '' })
      fieldList.push({ type: 'string', value: 'tenderUnitId', text: '投标单位', dictCode: 'tender_unit' })
      fieldList.push({ type: 'sel_depart', value: 'tenderDept', text: '投标部门' })
      fieldList.push({ type: 'string', value: 'tenderAmount', text: '投标金额（元）', dictCode: '' })
      fieldList.push({ type: 'string', value: 'projectMember', text: '项目组成员', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bidReview1', text: '标书一审人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bidReview2', text: '标书二审人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'businessFile', text: '商务附件', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bidMethod', text: '开标方式', dictCode: 'tender_bid_method' })
      fieldList.push({ type: 'string', value: 'fileType', text: '文件类型', dictCode: 'tender_file_type' })
      fieldList.push({ type: 'string', value: 'comments', text: '备注', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bpmStatus', text: '审核状态', dictCode: '' })
      this.superFieldList = fieldList
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
